unit FCrudContasPagar;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Buttons;

type
  TFCrudContasPagarFt = class(TForm)
    grupoLancamentoContasPagar: TGroupBox;
    botaoSalvar: TSpeedButton;
    botaoSair: TSpeedButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    botaoAlterar: TSpeedButton;
    txtIdContasPagar: TEdit;
    txtValor: TEdit;
    txtObservacoes: TMemo;
    txtDataPagamento: TDateTimePicker;
    procedure botaoSairClick(Sender: TObject);
    procedure botaoSalvarClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure botaoAlterarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function limparDados : Boolean;    
  end;

var
  FCrudContasPagarFt: TFCrudContasPagarFt;

implementation

uses URequestContasPagar, UContasPagarFt;

{$R *.dfm}

procedure TFCrudContasPagarFt.botaoSairClick(Sender: TObject);
begin
   Close;
end;

procedure TFCrudContasPagarFt.botaoSalvarClick(Sender: TObject);
begin
  req.acao := 'inserir';
  req.valor := StrToFloat(txtValor.Text);
  req.data_pagamento := txtDataPagamento.Date;
  req.observacoes := txtObservacoes.Lines.Text;

  TContasPagarFt.service(req);
  self.limparDados;
end;

function TFCrudContasPagarFt.limparDados : Boolean;
begin
  // self.txtDataRecebimento.Text := '';
  self.txtValor.Text := '';
  self.txtObservacoes.Text := '';

  self.txtDataPagamento.SetFocus;
end;

procedure TFCrudContasPagarFt.FormCreate(Sender: TObject);
begin
  inherited;
  // 
end;

procedure TFCrudContasPagarFt.FormDestroy(Sender: TObject);
begin
  inherited;
  // 
end;

procedure TFCrudContasPagarFt.botaoAlterarClick(Sender: TObject);
begin
  req.acao := 'atualizar';
  req.id_contaspagar := StrToInt(txtIdContasPagar.Text);
  req.valor := StrToFloat(txtValor.Text);
  req.data_pagamento := txtDataPagamento.Date;
  req.observacoes := txtObservacoes.Lines.Text;

  TContasPagarFt.service(req);
  self.limparDados;
  self.Close;
end;

end.
